Skip to content

Conversation

TheJulianJES
Copy link
Collaborator

@TheJulianJES TheJulianJES commented Jun 29, 2025

Proposed change

This adds a binary sensor entity for the Senoro door sensor that displays the current alarm state.
A button entity is also added that allows for resetting an activated tamper alarm.

This still needs testing

Additional information

Follow-up to:

Implementation details:

  • The tuya_switch (and so on) methods do three things: (1) map the Tuya DP to a ZCL attribute, (2) create that ZCL attribute, and (3) create the switch entity metadata. Here, we call tuya_dp_attribute to (1) map the DP and (2) create the ZCL attribute. We call binary_sensor and write_attr_button methods directly for the mapped ZCL attribute.
  • translation_key is omitted for the "Tamper" alarm, as we set the "tamper device class", defaulting to a translated "Tamper" name in Home Assistant
  • unique_id_suffix is only kind of needed for the binary sensor and button entity. The unique ID for the HA entities is based on the attribute_name by default, which would conflict. However, unique IDs are still keyed by platform (binary_sensor vs button in ZHA), so they won't conflict for now. Still, we want to avoid this, so I've given them separate unique_id_suffixes.

Checklist

  • The changes are tested and work correctly
  • pre-commit checks pass / the code has been formatted using Black
  • Tests have been added to verify that the new code works

@TheJulianJES TheJulianJES added the Tuya Request/PR regarding a Tuya device label Jun 29, 2025
Copy link

codecov bot commented Jun 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.28%. Comparing base (79df871) to head (426294c).
⚠️ Report is 7 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #4155   +/-   ##
=======================================
  Coverage   91.28%   91.28%           
=======================================
  Files         339      339           
  Lines       10967    10968    +1     
=======================================
+ Hits        10011    10012    +1     
  Misses        956      956           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@senorosoftware
Copy link

senorosoftware commented Jun 29, 2025

@TheJulianJES
This implementation seems to work. I tested it with a device, There is a switch button that show "Tamper Alarm". The state of the button doesn't change if the alarm starts. The Manipulation field under "Sensor" is showing the correct state, if the alarm starts. Also the opening state and the battery works as expected. Resetting the alarm (turn off) via the "Reset Alarm" "Press" button works fine.

image

@felixmueller
Copy link

@TheJulianJES

Looks good for me, too. I don't have the "Tamper alarm" button, maybe that was just cached by HA @senorosoftware?

I didn't try if the "Reset alarm" control works because I don't want to trigger the alarm right now.

Will this update be also part of the next release used by HA 2025.7?

Thanks a lot!

sonoro_quirk

@ChristianGr1974
Copy link
Contributor

@TheJulianJES

Looks good for me, too. I don't have the "Tamper alarm" button, maybe that was just cached by HA @senorosoftware?

I didn't try if the "Reset alarm" control works because I don't want to trigger the alarm right now.

Will this update be also part of the next release used by HA 2025.7?

Thanks a lot!

sonoro_quirk

@felixmueller
You are right, the switch is cached. I didn‘t reconnected the device.

@felixmueller
Copy link

@TheJulianJES

Can this be merged now that the test from @senorosoftware was successful? Thanks!

@ChristianGr1974
Copy link
Contributor

@TheJulianJES
When can this PR be completed?

@TheJulianJES TheJulianJES merged commit 9b69936 into zigpy:dev Jul 25, 2025
9 checks passed
@TheJulianJES TheJulianJES deleted the tjj/senoro_door_sensor_alarm branch July 25, 2025 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tuya Request/PR regarding a Tuya device
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants